<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
    :dialogWidth="dialogWidth"
  >
    <template #searchPanel>
      <search-panel
        v-slot="{ form }"
        :addPer="'outStorage:save'"
        :selectPer="'outStorage:page'"
        addTitle="新增出库"
        @insert="add"
        @search="search"
        @export="handleDataExport('OutStorage','出库数据')"
        :showSearchButton="true"
        :showAddButton="true"
        :showExportButton="true"
      >
        <Job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select
          clearable
          style="width: 200px"
          v-model="form.storageType"
          placeholder="出库类型"
        >
          <el-option
            v-for="item in dict['出库类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.likeName"
          clearable
          placeholder="出库编号/负责人"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="view"
      >
        <template #action="{ row }">
          <!-- <i
            v-if="row.auditStatus != '无' && row.auditStatus != null"
            title="审核"
            class="cursor"
            v-permission="'outStorage:update'"
            :style="{color: row.auditStatus == '待审核' ? 'blue' : row.auditStatus == '已审核' ? 'green' : row.auditStatus == '已拒绝' ? 'red' : 'black'}"
            :disabled="row.auditStatus != '待审核'"
            @click="handleAudit(row)"
          >审</i> -->
          <i
            v-if="row.auditStatus == '待审核'"
            title="审核"
            class="cursor"
            style="color: blue"
            v-permission="'outStorage:update'"
            @click="handleAudit(row)"
          >审</i>
          <i
            v-if="row.status != '已出库'"
            class="el-icon-edit cursor ml_15"
            title="编辑"
            v-permission="'outStorage:update'"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete cursor ml_15"
            title="删除"
            style="color: red"
            v-permission="'outStorage:del'"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail :id="viewId"  v-if="dialogTitle == '出库详情'"/>
      <dialog-data-form :id="viewId" v-if="dialogTitle == '出库审核'" @operate="handleDataOperate"/>
    </template>
  </base-layout>
</template>
<script>
import baseMixin from "@/mixins/base";
import { page, deleteById } from "@/api/after-sale/storehouseManage/outOfStockManage";
import { getDict } from "@/utils";
import DialogViewDetail from "./view/index";
import DialogDataForm from './components/DialogDataForm.vue'
export default {
  components: {
    DialogViewDetail,
    DialogDataForm
  },
  mixins: [
    baseMixin({
      idName: "id",
      findData: page,
      dataName: ["content", "totalRecords"],
      format(res) {
        return res.map((data) => {
          return data;
        });
      },
      deleteData: deleteById,
    }),
  ],
  data() {
    return {
      dialogWidth: "1200px",
      tableColumnAttributes: [
        { name: "所属门店", value: "storeName", type: "text" },
        { name: "出库编号", value: "outStorageCode", type: "text" },
        { name: "出库类型", value: "outStorageType", type: "text" },
        { name: "出库仓库", value: "storageName", type: "text" },
        { name: "仓库编号", value: "storageCode", type: "text" },
        { name: "出库负责人", value: "userName", type: "text" },
        { name: "负责人联系方式", value: "phone", type: "text" },
        { name: "单据日期", value: "receiptsTime", type: "text" },
        { name: "出库配件数量", value: "partsNum", type: "text" },
        { name: "出库总金额", value: "amount", type: "text" },
        { name: "出库备注", value: "remark", type: "text" },
        { name: "出库状态", value: "status", type: "text" },
        { name: "审核状态", value: "auditStatus", type: "text" },
        { name: "录入时间", value: "createTime", type: "text" },
      ],
      viewId: null,
      dict: [],
    };
  },
  methods: {
    add() {
      this.$router.push({ path: "/partsStock/partsStockManage/addOutOfStockManage" });
    },
    handleDataUpdateEdit(row, type) {
      this.$router.push({
        path: "/partsStock/partsStockManage/editOutOfStockManage",
        query: {
          id: row.id,
        },
      });
    },
    search(form) {
      this.searchOptions = form;
      this.currentPage = 1;
      this.setTableData();
    },
    // 查看入库
    view(row) {
      this.viewId = row.id;
      this.dialogWidth = "1200px";
      this.handleDataInsert("出库详情");
    },
    handleAudit(row) {
      this.viewId = row.id;
      this.dialogWidth = "500px";
      this.handleDataInsert('出库审核');
    }
  },
  mounted() {
    this.dict = getDict(["出库类型"]);
  },
};
</script>
<style lang="scss" scoped>
  .cursor {
    cursor: pointer;
  }
  .ml_15 {
    margin-left: 15px;
  }
  /deep/ .el-dialog{
  min-width: 500px !important;
}
</style>
